package com.beta.cat.exception;


/**
 * @Description 校验异常
 * @Author lixin
 **/
public class ValidException extends Exception {
    private CommonAPICode apiCode;

    public ValidException() {
    }

    public ValidException(CommonAPICode apiCode) {
        this.apiCode = apiCode;
    }

    public CommonAPICode getApiCode() {
        return apiCode;
    }

    public void setApiCode(CommonAPICode apiCode) {
        this.apiCode = apiCode;
    }

    public static enum CommonAPICode {
        SUCCESS(200, "success"),
        INVALID_LOGIN_STATUS(301, "invalid login status"),
        USER_TOKEN_INVALID(302, "user token invalid"),
        ERROR_CODE_1001(1001, "接口访问异常，请联系客服人员！"),

        /**
         * 客户端数据错误
         */
        POST_DATA_ERROR(30001, "Client submit data error", "客户端提交数据错误"),
        ACTIVITY_IS_OVER(30002, "活动已结束", ""),
        ;
        private int code;
        /**
         * 英文描述
         */
        private String message;
        /**
         * 中文描述
         */
        private String desc;

        CommonAPICode(int code, String message) {
            this.code = code;
            this.message = message;
        }

        CommonAPICode(int code, String message, String desc) {
            this.code = code;
            this.message = message;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }

        public String getDesc() {
            return desc;
        }

        //
        public static boolean isOk(CommonAPICode apiCode) {
            if (apiCode == CommonAPICode.SUCCESS) {
                return true;
            }
            return false;
        }

    }
}
